package com.game.sdk.util;

import java.io.InputStream;

import android.content.Context;
import android.os.AsyncTask;

/****
 * 请求 params[0] context ；params[1] ；url params[2] 请求参数； params[3] 请求是否加密
 * ；params[4] 请求是否压缩 ；params[5] 响应是否加密；params[6] 响应是否压缩
 * */
public class NetTask extends AsyncTask<Object, Integer, String> {
	public static final int PARAMS_COUNT = 7;

	@Override
	protected String doInBackground(Object... arg0) {
		String respose = null;
		if (checkParams(arg0)) {
			Context ctx = (Context) arg0[0];// 上下文
			String url = (String) arg0[1];// url
			String jsonParams = (String) arg0[2];// 请求参数
			boolean isEncode = (Boolean) arg0[3];// 是否编码
			boolean isZip = (Boolean) arg0[4];// 是否压缩
			boolean isResponseDecode = (Boolean) arg0[5];// service是否加密
			boolean isResponseUnzip = (Boolean) arg0[6];// service是否压缩
			InputStream is = GetDataImpl.getInstance(ctx).doRequest(url,
					jsonParams, isEncode, isZip);
			if(is!=null){
				respose = Encrypt.readNetStream(is, isResponseDecode,
						isResponseUnzip);
			}
		} 
		return respose;
	}

	/***
	 * 检测参数的有效性，以后这个函数要完善
	 * */
	private boolean checkParams(Object... params) {
		boolean checked = true;
		if (params.length < PARAMS_COUNT) {
			checked = false;
			return checked;
		}
		return checked;
	}
}
